<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text">
    <input type="submit">
    <script>
        let inputs = document.querySelectorAll('input');
        inputs[1].addEventListener('click', () => {
            let val = inputs[0].value;
            let RE1 = /^[0-9a-zA-Z]{8,12}$/;
            if (RE1.test(val)) {
                alert('用户名格式正确');
            } else {
                alert('用户名格式错误');
            };
        });
    </script>
</body>

</html>